package spring.cloud.tasks.executor.executor.task.execute_statistics;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.common.nodepaths.TaskNodePaths;
import spring.cloud.tasks.executor.executor.task.TaskExecutor;
import spring.cloud.tasks.executor.executor.task.TaskListenerHolder;

@Slf4j
@Setter
@Getter
public class ExecuteStatisticsResetListenerHolder extends TaskListenerHolder {
    public boolean isShutdown = false;

    public ExecuteStatisticsResetListenerHolder(TaskExecutor taskExecutor) {
        super(taskExecutor);
    }

    @Override
    public void start() {
        taskExecutorNodeCacheOrTreeCacheManager.addTreeCacheListener(TaskNodePaths.getTaskNodePath(taskId, ExecuteStatisticsNode.reset_statistics), 0, new ExecuteStatisticsResetListener(this));
    }

    @Override
    public void stop() {
        super.stop();
        isShutdown = true;
        taskExecutorNodeCacheOrTreeCacheManager.closeTreeCache(TaskNodePaths.getTaskNodePath(taskId, ExecuteStatisticsNode.reset_statistics), 0);
    }

}
